SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO





ALTER    VIEW  v_tb_expenditure  
as  
select cast(0 as bit) choice,410 btype,m.bcode m_bcode,m.bdate m_bdate,m.remark m_remark,m.bkind m_bkind,m.bstate m_bstate,m.bid m_bid,  
       m.create_by m_create_by,m.filid m_filid,m.check_by m_check_by,m.empid m_empid,m.traderid m_traderid,m.contacter m_contacter,  
       m.balanceid m_balanceid, m.accountid m_accountid,m.deptid m_deptid,m.voucherid m_voucherid,  
       m.moneyid m_moneyid,mn.code moneycode,mn.name moneyname,m.exchrate m_exchrate,m.workshopid m_workshopid,
   m.custom1 m_custom1,m.custom2 m_custom2,m.custom3 m_custom3,m.custom4 m_custom4,m.custom5 m_custom5,
   m.custom6 m_custom6,m.custom7 m_custom7,m.custom8 m_custom8,m.custom9 m_custom9,m.custom10 m_custom10,
   m.custom11 m_custom11,m.custom12 m_custom12,m.custom13 m_custom13,m.custom14 m_custom14,m.custom15 m_custom15, 
  m.projectid m_projectid,pj.code m_pjcode,pj.name m_pjname,  
  ct.name + ' ' + cast(vou.voucherno as varchar(10)) as m_vouchercode,
       d.*,  
       dbo.f_getrelationbcode(d.relationbtype,d.relationbid) as relationbcode,
       e.id id,e.name as iename,e.subcode as code,df.fi_filnm filname  
from     tb_expenditure m  
left join tb_expendituredtl  d   on m.bid=d.bid  
left join td_money mn on m.moneyid=mn.moneyid
left join td_expend          e    on d.ietypeid=e.id  
left join tfb_voucher vou on (vou.voucherid=m.voucherid)  
left join tfd_vouword ct on (ct.id=vou.vouwordid)  
left join td_balance   b on b.balanceid=m.balanceid  
left join td_account   c on c.accid=m.accountid  
--left join v_Td_Account v on v.bankid=c.bankid  
left join td_dept      q on q.ED_DeptID=m.deptid  
left join ts_usersinfo cr on m.create_by=cr.ui_userid  
left join ts_usersinfo ck on m.check_by=ck.ui_userid  
left join td_empmaster em on m.empid = em.em_employeeid  
left join td_filiale f on m.filid=f.fi_filid  
left join td_filiale df on d.filid=df.fi_filid  
left join td_trader  t on t.TraderId=m.traderid  
  left join tfd_project pj on m.projectid=pj.id

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

